#include <unistd.h>
#include <malloc.h>
#include <iostream>
#include <string.h>
#include "RPCheader.h"

int main ( void ) {

  int argTypes[3];
  void **args = (void **)malloc(2 * sizeof(void *));

  int argTypes1[3];
  void **args1 = (void **)malloc(2 * sizeof(void *));

  // void copyChar(dest, src);

  int result = 23;                         // Why 23?  Why not 23?
  char dest = 'd';
  char src  = 's';
  argTypes[0] = rpcChar | rpcOutput;       // dest
  argTypes[1] = rpcChar | rpcInput;        // src
  argTypes[2] = 0;                         // Terminator

  args[0] = (void *)&dest;
  args[1] = (void *)&src;

  std::cerr << "Before: " << dest << ", " << src << std::endl;
  result = rpcCall("copyChar", argTypes, args);
  std::cerr << "After: " << dest << ", " << src << " with result: " << result << std::endl;

  int result1 = 22;
  char dest1 = 'd';
  char src1  = 's';
  argTypes1[0] = rpcChar | rpcOutput;       // dest
  argTypes1[1] = rpcChar | rpcInput;        // src
  argTypes1[2] = 0;                         // Terminator

  args1[0] = (void *)&dest1;
  args1[1] = (void *)&src1;

  std::cerr << "Before: " << dest1 << ", " << src1 << std::endl;
  result1 = rpcCall("copyChar", argTypes1, args1);
  std::cerr << "After: " << dest1 << ", " << src1 << " with result: " << result1 << std::endl;


  // The displayParms() test case will accept
  // arbitrary arguments and will simply display
  // their value.  This allows testing of the
  // various parameter passing mechanisms.

  // displayParms( ... )

  int* vector  = (int*)malloc(4*sizeof(int));
  vector[0] = 12;
  vector[1] = 13;
  vector[2] = 1;
  vector[3] = 99;
  char x = 'h';
  char *y = "fishies";
  char *z[3] = {"fish","and","chips"};

  argTypes[0] = rpcInt    |     rpcInput | rpcPartialMatch;   // Result
  argTypes[1] = rpcInt    | 4 | rpcInput | rpcPartialMatch;   // Vector
  argTypes[2] = rpcChar   |     rpcInput | rpcPartialMatch;   // x
  argTypes[3] = rpcString |     rpcInput | rpcPartialMatch;   // y
  argTypes[4] = rpcString | 3 | rpcInput | rpcPartialMatch;   // z
  argTypes[5] = 0;                                            // Terminator

  args[0] = (void *)&result;
  args[1] = (void *) vector;
  args[2] = (void *)&x;
  args[3] = (void *) y;
  args[4] = (void *) z;

  //std::cerr << "Y is " << y << std::endl
	//    << "&Y is " << &y << std::endl
	  //  << "Z is " << z << std::endl
	  //  << "&Z is " << &z << std::endl
	   // << z[0] << std::endl
	   // << z[1] << std::endl
	   // << z[2] << std::endl;

  //rpcCall("displayParms", argTypes, args);

  //rpcTerminate();

  return 0;
}
